package com.frkj.yuan.api.presenter;
import com.frkj.yuan.api.bean.AddJiuzhenPersonBean;
import com.frkj.yuan.api.bean.BaseInforBean;
import com.frkj.yuan.api.bean.SelectServiceTimeBean;
import com.frkj.yuan.api.category.AddAutherBean;
import com.frkj.yuan.api.category.AddJiuzhenPersonCategory;
import com.frkj.yuan.utils.RetrofitUtil;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

import java.io.IOException;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import okhttp3.ResponseBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;
/**
 * 信息说明:
 * company: 兰州丰荣信息科技有限公司
 * 创建时间: on 2022/3/22 16 ：59
 * 项目名称：yuanban
 */
public class AddJiuzhenPersonPresenter implements AddJiuzhenPersonCategory.Presenter {
    AddJiuzhenPersonCategory.View view;
    public AddJiuzhenPersonPresenter(AddJiuzhenPersonCategory.View view) {
        this.view = view;
    }
    @Override
    public void getAutherMsg(String mToken, String cardNumber) {
        RetrofitUtil.getInstance().getmService().getAutherMsg(mToken,cardNumber).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                String result = null;
                try {
                    result = response.body().string();
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    AddAutherBean userInfor = gson.fromJson(result, AddAutherBean.class);
                    view.getAutherMsg(userInfor);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                view.OnShowErrorMsg(t.getMessage());
            }
        });
    }

    @Override
    public void getAddjiuzhenPerson(String token,String requestBody) {
        RequestBody  body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), requestBody);
        RetrofitUtil.getInstance().getmService().getAddJiuzhenPerson(token,body).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                String result = null;
                try {
                    result = response.body().string();
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    AddJiuzhenPersonBean userInfor = gson.fromJson(result, AddJiuzhenPersonBean.class);
                    view.getAddjiuzhenPerson(userInfor);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                view.OnShowErrorMsg(t.getMessage());
            }
        });
    }

    @Override
    public void getSelectTime(long hospitalId) {
        RetrofitUtil.getInstance().getmService().getSelectTime(hospitalId).enqueue(new Callback<ResponseBody>() {
            @Override
            public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
                String result = null;
                try {
                    result = response.body().string();
                    Gson gson = new GsonBuilder().serializeNulls().create();
                    SelectServiceTimeBean userInfor = gson.fromJson(result, SelectServiceTimeBean.class);
                    view.getSelectTime(userInfor);
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            @Override
            public void onFailure(Call<ResponseBody> call, Throwable t) {
                view.OnShowErrorMsg(t.getMessage());
            }
        });
    }
}
